<?php

class Easier_create_slider {
    
    static function get_options() {
        $data = ["slider-title", "tax_time", "number_post", "tax_categories", "sort_type", "order_by", "width", "height", "hide_slider", "back_fit", "align_slider", "effect_slider", "effect_time", "start_slide"];
        $data_title = "slider-title*". "tax_time*". "number_post*". "tax_categories*". "sort_type*". "order_by*". "width*"."height*". "hide_slider*"."back_fit*". "align_slider*". "effect_slider*"."effect_time*"."start_slide*";
        $list_title = explode("*", $data_title);
        for ($i = 0; $i < count($data); $i++) {
            $data[$i] = $_POST["$list_title[$i]"];
        }
        return $data;
    }
    
    static function get_posts_by($number_post, $cat) {
        //Documentation https://developer.wordpress.org/reference/functions/get_posts/
        //Like this
        $args = array(
            'numberposts' => $number_post,
            'category' => $cat
        );

        $post_for_slider = get_posts( $args );
        
        $data_post;
        $j;
        $i = 0;
        if ( $post_for_slider ) {
            foreach ( $post_for_slider as $post ) : 
                if ( has_post_thumbnail( $post->ID ) ) {
                    /*$j[0] = get_permalink( $post->ID );
                    $j[1] = esc_attr( $post->post_title );
                    $j[2] = get_the_post_thumbnail( $post->ID, 'full' );
                    
                    $data_post = $data_post . "<a href='" . $j[0] . "' title='" . $j[1] . "'>"
                    . $j[2] ."</a><br><br>";*/
                    $data_post[$i][0] = get_permalink( $post->ID );
                    $data_post[$i][1] = esc_attr( $post->post_title );
                    $data_post[$i][2] = get_the_post_thumbnail_url( $post->ID, 'full' );
                    $i++;
                }
            endforeach;
        }
        return $data_post;
    }
}

